﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sheep_Breeding.ErrorCode;
using Sheep_Breeding.Write.Api.DTOSheep;
using Sheep_Breeding.Write.Api.OperationServices.IServices;

namespace Sheep_Breeding.Write.Api.Controllers
{
    /// <summary>
    /// 羊场管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepfarmController : ControllerBase
    {
        private readonly ILogger<SheepfarmController> logger;
        private readonly ISheepfarmServices sheepfarmServices;

        public SheepfarmController(ILogger<SheepfarmController> logger, ISheepfarmServices sheepfarmServices)
        {
            this.logger = logger;
            this.sheepfarmServices = sheepfarmServices;
        }

        /// <summary>
        /// 新增羊场信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> CreateSheepfarm(CreateSheepfarmDto dto)
        {
            try
            {
                return await sheepfarmServices.CreateSheepfarm(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 修改羊场信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]

        public async Task<ApiResult> UpdateSheepfarm(UpdateSheepfarmDto dto)
        {
            try
            {
                return await sheepfarmServices.UpdateSheepfarm(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 更新羊场状态（启用/禁用）
        /// </summary>
        /// <param name="dto">更新状态DTO</param>
        /// <returns>返回操作结果</returns>
        [HttpPut]
        public async Task<ApiResult> UpdateSheepfarmStatus(UpdateSheepfarmStatusDto dto)
        {
            try
            {
                return await sheepfarmServices.UpdateSheepfarmStatus(dto);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }


        /// <summary>
        /// 羊场信息删除操作
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public async Task<ApiResult> DeleteSheepfarm(DeleteSheepfarmDto dto)
        {
            try
            {
                return await sheepfarmServices.DeleteSheepfarm(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 批量删除羊场信息
        /// </summary>
        /// <param name="dto">批量删除DTO</param>
        /// <returns>返回操作结果</returns>
        [HttpDelete]
        public async Task<ApiResult> BatchDeleteSheepfarms(BatchDeleteSheepfarmsDto dto)
        {
            try
            {
                return await sheepfarmServices.BatchDeleteSheepfarms(dto);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }


        /// <summary>
        /// 创建栋舍管理信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ApiResult> CreateBuildingManagement(CreateBuildingManagementDto dto)
        {
            try
            {
                return await sheepfarmServices.CreateBuildingManagement(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }


        /// <summary>
        /// 修改栋舍管理信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<ApiResult> UpdateBuildingManagement(UpdateBuildingManagementDto dto)
        {
            try
            {
                return await sheepfarmServices.UpdateBuildingManagement(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }


        /// <summary>
        /// 删除栋舍管理数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteBuildingManagement(DeleteBuildingManagementDto dto)
        {
            try
            {
                return await sheepfarmServices.DeleteBuildingManagement(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 批量删除栋舍信息
        /// </summary>
        /// <param name="dto">批量删除DTO</param>
        /// <returns>返回操作结果</returns>
        [HttpDelete]
        public async Task<ApiResult> BatchDeleteBuildingManagement(BatchDeleteBuildingManagementDto dto)
        {
            try
            {
                return await sheepfarmServices.BatchDeleteBuildingManagement(dto);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 更新栋舍状态（启用/禁用）
        /// </summary>
        /// <param name="dto">更新状态DTO</param>
        /// <returns>返回操作结果</returns>
        [HttpPut]
        public async Task<ApiResult> UpdateBuildingManagementStatus(UpdateBuildingManagementStatusDto dto)
        {
            try
            {
                return await sheepfarmServices.UpdateBuildingManagementStatus(dto);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 创建栏位管理
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> CreateField_management(CreateField_managementDto dto)
        {
            try
            {
                return await sheepfarmServices.CreateField_management(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 更新栏位管理
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateField_management(UpdateField_managementDto dto)
        {
            try
            {
                return await sheepfarmServices.UpdateField_management(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 删除栏位管理 
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteField_management(DeleteField_managementDto dto)
        {
            try
            {
                return await sheepfarmServices.DeleteField_management(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }


    }
}
